using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

[assembly: WebResource("SharpPieces.Web.JQuery.blockUI.jquery.blockUI.js", "text/javascript")] //, PerformSubstitution = true
[assembly: WebResource("SharpPieces.Web.JQuery.blockUI.BlockUI.js", "text/javascript")] //, PerformSubstitution = true
namespace SharpPieces.Web.JQuery
{
    public class BlockUI : BaseJQueryControl
    {
        // from http://www.malsup.com/jquery/block/#overview
        Panel _pnlTemplate;
        public BlockUI()
        {
            this.Init += new EventHandler(BlockUI_Init);
            this.PreRender += new EventHandler(BlockUI_PreRender);

            _pnlTemplate = new Panel();
            _pnlTemplate.ID = "tpl";
        }

        void BlockUI_Init(object sender, EventArgs e)
        {
            Controls.Add(_pnlTemplate);
        }

        void BlockUI_PreRender(object sender, EventArgs e)
        {
            if (ScriptManager.GetCurrent(this.Page) == null)
                throw new Exception("A ScriptManager control needs to be placed on the page!");
        }


        public string WaitMessage
        {
            get
            {
                if (_pnlTemplate.Controls.Count == 0)
                    return string.Empty;
                else
                    return (this._pnlTemplate.Controls[0] as LiteralControl).Text;
            }
            set
            {
                this._pnlTemplate.Controls.Clear();
                this._pnlTemplate.Controls.Add(new LiteralControl(value));
            }
        }

        protected override IEnumerable<KeyValuePair<string, object>> GetJQueryObjectProperties()
        {
            yield return new KeyValuePair<string, object>("ContentElementID", "#" + _pnlTemplate.ClientID);
        }

        protected override IEnumerable<KeyValuePair<string, string>> GetJQueryObjectEvents()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        protected override IEnumerable<ScriptReference> GetJQueryScriptReferences()
        {
            yield return new ScriptReference(Page.ClientScript.GetWebResourceUrl(this.GetType(), "SharpPieces.Web.JQuery.blockUI.jquery.blockUI.js"));
            yield return new ScriptReference(Page.ClientScript.GetWebResourceUrl(this.GetType(), "SharpPieces.Web.JQuery.blockUI.BlockUI.js"));
        }

        protected override IEnumerable<string> GetClientStyleReferences()
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
